class PageController < ApplicationController
  before_filter :login_required, :only => [ :comment ]
  before_filter :load_page

  def show
    respond_to do |wants|
      wants.html # show.html.erb
      wants.xml { render :xml => @page.to_xml }
    end
  end

  def edit
  end

  def update
    @page.update_attributes(params[:page])
    flash[:notice] = "Your edits to #{@page.title} have been saved."
    respond_to do |wants|
      wants.html { redirect_to @page }
      wants.xml { render :xml => @page.to_xml }
      wants.js # update.js.rjs
    end
  end
  
  private
  
  def load_page
    @title = params[:title]
    unless @page = current_wiki.pages.find_by_title(@title)
      @page = current_wiki.pages.build( :title => @title )
    end
    @revision = @page.revisions.last
    @revision ||= Revision.new
  end
end
